package com.tairanchina.md.meeting.rabbit;



import com.tairanchina.md.elife.rabbit.client.consumer.RabbitConsumerClient;
import com.tairanchina.md.elife.rabbit.constants.ConnConstants;
import com.tairanchina.md.elife.rabbit.task.RabbitMQTask;
import com.tairanchina.md.meeting.constants.MeetingConstants;
import com.tairanchina.md.meeting.constants.MeetingProvider;

import com.tairanchina.md.mallorder.order.dto.YearPartyLikeDto;

import com.tairanchina.md.meeting.entity.YearMeetingProgram;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



/**用户点赞消费者处理任务
 * Created by lxliuxuan on 2016/12/27.
 */

public class ProgramLikeTask implements RabbitMQTask,Runnable{
    private Logger logger = LoggerFactory.getLogger(ProgramLikeTask.class);
    @Override

    public void consumerMsg(Object obj,Object... objects) throws Exception {
        YearPartyLikeDto likeDto = (YearPartyLikeDto) obj;


        //查询节目是否存在
        YearMeetingProgram program = MeetingProvider.programService.findProgramById(likeDto.getProgramId());


        if(program != null){

            //更新打赏信息
            program.setLikeNum(program.getLikeNum()+1);
            MeetingProvider.programService.updateProgram(program);
        }
    }
    @Override
    public void run(){

        RabbitConsumerClient consumerClient = ConnConstants.getConsumerClient();

        //处理接收消息
        while (true) {
            try {
                consumerClient.receiveMessage(MeetingConstants.QUEUE_NAME_YEAR_VOTE,this);
                Thread.sleep(100);
            } catch (Exception e) {
                e.printStackTrace();
                logger.error("更新点赞信息失败。e:{}",e);
            }
        }
    }
}
